package com.ztesoft.report.utils;



import com.ztesoft.report.base.pojo.TreeNode;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author y3tu
 * @date 2018/2/27
 */
public class TreeUtil {
    public static List<TreeNode> getNodeList(Map<String, TreeNode> nodelist) {
        List<TreeNode> tnlist = new ArrayList<>();
        for (String id : nodelist.keySet()) {
            TreeNode node = nodelist.get(id);
            if (StringUtils.isEmpty(node.getParentId()) || node.getParentId().equals("0")) {
                tnlist.add(node);
            } else {
                if (nodelist.get(node.getParentId()).getNodes() == null) {
                    nodelist.get(node.getParentId()).setNodes(new ArrayList<TreeNode>());
                    nodelist.get(node.getParentId()).getNodes().add(node);
                } else {
                    nodelist.get(node.getParentId()).getNodes().add(node);
                }
            }
        }
        return tnlist;
    }
}
